<template>
	<view class="popup_content">
		<view class="popup_header">
			<view>拆分</view>
			<view class="f_red">拆分金额：1025.00</view>
			<view @click="Cfclose">X</view>
		</view>
		<view class="popup_radio">
			<view class="popup_borderB">
				<radio-group @change="handleRadioChange" v-model="selectedValue">
					<radio value="1"  color="#fc4141" />随机拆分
					<radio value="2" color="#fc4141" class="m_l" checked="true"/>自定义拆分
				</radio-group>
			</view>
			<view v-if="selectedValue==1" class="radio_content">
				<view style="text-align: center;">每份价格不低于2000</view>
				<view class="input_text" >
					<input  type="text" v-model="num"/>
				</view>
			</view>
			<view v-else class="radio_content">
				<view style="text-align: center;">当前拆分：<span class="f_red">{{forms.length}}</span>单</view>
				<view class="input_text" v-for="(item,index) in forms" :key="item.id">
					<remove :show="index !=0" @remove="delItem" :value.sync="item.value"></remove>
				</view>
				<view>
					<button class="add_btn" @click="addItem">+添加</button>
				</view>
			</view>
			
		</view>
		<view><button class="cf_btn" @click="CfConfirm">确认拆分</button></view>
	</view>
</template>

<script>
	import remove from '@/components/remove.vue'
	export default {
			components: {
				remove
			},
			data() {
				return {
					selectedValue: '' ,// 初始化为空字符串,
					forms: [
						{
							id:"0",
							value: '2000'
						},
					],
					num: 1
				};
			},
			methods: {
				handleRadioChange(event) {
				    this.selectedValue = event.mp.detail.value;
				},
				CfToggle() {
					this.$refs.Cfpopup.open('center')
				},
				Cfclose() {
					this.$emit('close')
					//this.$refs.Cfpopup.close()
				},
				addItem(){
					this.forms.push({id: this.forms.length, value: ''})
				},
				delItem(){
					this.forms.pop()
				},
				CfConfirm(){
					if(this.selectedValue==1){
						this.$emit('CfConfirm',this.selectedValue, this.num)
					} else {
						this.$emit('CfConfirm',this.selectedValue, this.forms)
					}
				}
			}
		}
	</script>
</script>

<style scoped>
	/*弹出层*/
	.f_red {
		color: #fc4141;
	}
	.popup_p10{
		padding: 10px 0px;
	}
	.popup_borderB{	
		border-bottom: 1px solid #eee;
	}
	.m_l{ margin-left: 20px;}
	
	.popup_content{
		display:flex;
		flex-direction: column;
		width: 600px;
		height: 450px;
		background: #fff;
		border-radius: 10px;
		align-items: stretch;
		justify-content: flex-start;
		color: #999;
		padding: 10px 10px;
	}
	.popup_content .popup_header{
		display: flex;
		width: 100%;
		flex-direction: row;
		justify-content: space-between;
		padding: 11px 0;
		border-bottom: .5px solid #eee;
	}
	.popup_content .popup_radio{
		display: flex;
		flex-direction: column;
	}
	.popup_radio view{
	   padding: 5px 0px;
	}
	.radio_content{
		display: flex; 
		justify-content: center; 
		flex-direction: column; 
		align-items: stretch;
	}
	.popup_content .radio_content .input_text {
		margin: 0px 30px;
	}
	.popup_content .radio_content .input_text input{
		border: 2px solid #eee;
		display: flex;
		flex: 1;
		justify-content: center;
		height: 30px;
		
	}
	.popup_content .cf_btn{
		background: #fc4141;
		color: #fff;
		text-align: center;
		justify-content: center;
		display: flex;
		height: 30px;
		font-size: 14px;
		line-height: 30px;
		margin: 10px 30px;
	}
	.delbtn_style input[type='text'] {
	  border: none; /* 去除默认边框样式 */
	  outline: none; /* 去除默认外边框样式 */
	  padding: 8px;
	  font-size: 16px;
	  background-color: #f2f2f2;
	  box-shadow: inset 0 0 4px rgba(0, 0, 0, .3);
	  border-radius: 4px;
	  width: calc(100% - 70px); /* 根据需求调整输入框宽度 */
	}
	.delbtn_style button {
	  position: absolute;
	  top: 9px;
	  right: 9px;
	  display: inline-block;
	  padding: 4px 12px;
	  font-size: 14px;
	  color: white;
	  background-color: red;
	  cursor: pointer;
	  border: none;
	  border-radius: 4px;
	}
	.add_btn{
		background:lightblue;
		color:#2866f9;
		text-align: center;
		justify-content: center;
		display: flex;
		height: 35px;
		font-size: 16px;
		line-height: 30px;
		border:2px dotted #2866f9;
		margin: 0px 30px;
	}
</style>